<!DOCTYPE html>
<html>
<head>
    <title>受限制用户管理</title>
	<#include "/common/import.ftl" >
    <script type="text/javascript">
        $(function () {
            //获取黑名单冻结列表,解冻只需要将IP设为空
            $('#cacheList').datagrid({
                title: '受限制用户管理<数据25小时后刷新,此数据只供参考>',
                iconCls: 'icon-ok',
                url: '${ctx}/passport/cache/list!data.action',
                nowrap: false,
                striped: true,
                collapsible: false,
                fitColumns: true,
                pagination: true,
                singleSelect: true,
                rownumbers: true,
                remoteSort: false,
                pageList: [15, 20, 30, 50],
                columns: [[
                    {field: 'userEname', title: '登录账户', width: 60, sortable: true},
                    {
                        field: 'loginCount',
                        title: '登录次数限制',
                        width: 80,
                        sortable: true,
                        formatter: function (value) {
                            var count = Number(value);
                            switch (count) {
                                case 3:
                                    return "登录错误3次|已锁定|10分钟后可登录";
                                    break;
                                case 6:
                                    return "登录错误6次|已锁定|30分钟后可登录";
                                    break;
                                case 9:
                                    return "登录错误9次|已锁定|24小时后可登录";
                                    break;
                                case 12:
                                    return "<font color=\"red\">登录错误12次|已冻结|请联系系统管理员</font>";
                                    break;
                                default:
                                    return "登录错误" + count + "次";
                            }
                        }
                    },
                    {field: 'loginTime', title: '登录时间', width: 130, sortable: true}
                ]],
                toolbar: [{
                    text: '限制移除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        deleteCache();
                    }
                }, '-', {
                    text: '刷新缓存',
                    iconCls: 'icon-reload',
                    handler: function () {
                        cacheReload();
                    }
                }
                ]
            });
        });

        // 判断是否选中一条记录
        function getSelected() {
            var selected = $('#cacheList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        // 刷新列表
        function cacheReload() {
            $('#cacheList').datagrid('reload');
        }

        //强制退出
        function deleteCache() {
            var node = getSelected();
            if (node) {
                $.messager.confirm('确认', '您确定要删除:<font color=red>' + node.userEname + '</font> ?', function (r) {
                    if (r) {
                        $.ajax({
                            type: "post",
                            url: "${ctx}/passport/cache/del.action?id=" + node.cacheId,
                            dataType: "json",
                            success: function (data) {
                                var result = data;//jQuery.parseJSON(data);
                                if (result.flag == 'T') {
                                    $.messager.alert('结果', '操作成功', 'info');
                                    var rowIndex = $('#cacheList').datagrid('getRowIndex', node);
                                    $('#cacheList').datagrid('deleteRow', rowIndex);
                                    cacheReload();
                                } else if (result.flag == 'H') {
                                    $.messager.alert('结果', result.msg, 'info');
                                } else {
                                    $.messager.alert('结果', '操作失败，请重试', 'error');
                                }
                            },
                            error: function (messg) {
                                $.messager.alert('错误提示', '操作失败:' + messg.responseText, 'error');
                            }
                        });
                    }
                });
            }
        }
    </script>
</head>
<body>
<table id="cacheList"></table>
</body>
</html>